<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="com.base.myproject.server.tools.*" %>
<%@ page import="com.base.myproject.client.jdbc.DataSet,java.util.Date" %>
<%@page import="java.text.SimpleDateFormat,java.util.Calendar,java.math.BigDecimal"%>
<%@ page import="com.google.gwt.i18n.client.*" %>
<%@ page import="com.google.gwt.i18n.client.DateTimeFormat" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<%
	response.setHeader("Content-disposition","attachment; filename=hostelSalary.xls");
	String searchDate = request.getParameter("searchDate");
	String hostel = request.getParameter("hostel");
	String type = request.getParameter("type");
	
	DataSetTool DST = new DataSetTool();
	String sql = "select desc_cn,ROUND(amount,2) as amount,convert(varchar(10),adddate,120) as adddate,b.name,b.employno,b.bname,convert(varchar(10),a.createdate,120) as createdate,others from hr_salary_ext a inner join systemName_bcode b on a.bcode = b.bcode inner join hr_Salary_Item c on a.code = c.code where (a.code='D02' or a.code='D01') and others is not null";
	
	if (!searchDate.equals("0")) {
		sql += " and datediff(month,'"
			+ searchDate
			+ "',adddate )=0 ";
	}
	
	if (!hostel.equals("0")) {
		 sql += " and others = '" + hostel + "'";
	}
	
	if (!type.equals("0")) {
		sql += " and a.code = '" + type + "'";
	}
	
	sql += " order by others";
		
	DataSet dsDepartment = DST.getDataSet(sql);
	String code = "";
	double sum = 0.0;
	double allSum = 0.0;
%>
</head>
<body>
	<table style="border-collapse: collapse" border="1" align="center"  cellspacing="0" cellpadding="3" border="1" width="100%" bordercolordark="#CCCCCC" bordercolorlight="#CCCCCC" style="border-color:#000000;">
		<tr bgcolor="#e8e8e0" align="center">
			<td>发生日期</td>
			<td>费用类型</td>
			<td>雇员编号</td>
			<td>雇员姓名</td>
			<td>部门</td>
			<td>添加日期</td>
			<td>金额</td>
		</tr>
		<% for(int i = 0;i <  dsDepartment.getRowCount();i++){ 
			sum += Double.parseDouble(dsDepartment.getValue(i,"amount"));
			if (!dsDepartment.getValue(i,"others").equals(code)) {
				code = dsDepartment.getValue(i,"others");
		%>
		<tr>
			<td bgcolor="#cccc77" colspan="7" height="24">宿舍编号：<%= code %></td>
		</tr>
		<%		
			}
		%>
			
		<tr>
			<td><%= dsDepartment.getValue(i,"adddate") %></td>
			<td><%= dsDepartment.getValue(i,"desc_cn") %></td>
			<td><%= dsDepartment.getValue(i,"employno") %></td>
			<td><%= dsDepartment.getValue(i,"bname") %></td>
			<td><%= dsDepartment.getValue(i,"name") %></td>
			<td><%= dsDepartment.getValue(i,"createdate") %></td>
			<td><%= RPTString2Double.string2String(dsDepartment.getValue(i,"amount")) %></td>
		</tr>
		
		<%	
			if ((i + 1) == dsDepartment.getRowCount() || !dsDepartment.getValue(i + 1,"others").equals(code)) {
		%>
		<tr>
			<td bgcolor="#cccc77" align="right" colspan="7" height="24">宿舍编号：<%= code %>费用总合：<%= RPTString2Double.double2String(sum)%></td>
		</tr>
		<%		
				allSum += sum;
				sum = 0.0;
			}
		} 
		%>
		<tr>
			<td bgcolor="#cccc77" align="right" colspan="7" height="24">总费用：<%= RPTString2Double.double2String(allSum)%></td>
		</tr>
	</table>
</body>
</html>
